Crate bgpkit_broker
source ·Expand description
§Overview
bgpkit-broker is a package that allow access the BGPKIT Broker API and search for BGP archive files with different search parameters available.
§Examples
§Using Iterator
The recommended usage to collect BrokerItems is to use the built-in iterator. The BrokerItemIterator handles making API queries so that it can continuously stream new items until it reaches the end of items. This is useful for simply getting all matching items without need to worry about pagination.
use bgpkit_broker::{BgpkitBroker, BrokerItem};
let broker = BgpkitBroker::new()
.ts_start("1634693400")
.ts_end("1634693400");
// method 1: create iterator from reference (so that you can reuse the broker object)
// same as `&broker.into_iter()`
for item in &broker {
println!("{}", item);
}
// method 2: create iterator from the broker object (taking ownership)
let items = broker.into_iter().collect::<Vec<BrokerItem>>();
assert_eq!(items.len(), 106);
§Making Individual Queries
User can make individual queries to the BGPKIT broker backend by calling BgpkitBroker::query_single_page function.
Below is an example of creating an new struct instance and make queries to the API:
use bgpkit_broker::BgpkitBroker;
let mut broker = BgpkitBroker::new()
.ts_start("1634693400")
.ts_end("1634693400")
.page(3)
.page_size(10);
let res = broker.query_single_page();
for data in res.unwrap() {
println!("{} {} {} {}", data.ts_start, data.data_type, data.collector_id, data.url);
}
broker.turn_page(4);
let res = broker.query_single_page();
for data in res.unwrap() {
println!("{} {} {} {}", data.ts_start, data.data_type, data.collector_id, data.url);
}
Making individual queries is useful when you care about specific pages, or want to implement customized iteration procedure. Use BgpkitBroker::turn_page to manually change to a different page.
§Getting the Latest File for Each Collector
We also provide way to fetch the latest file information for each collector available with the BgpkitBroker::latest call. The function returns JSON-deserialized result (see [CollectorLatestItem]) to the RESTful API at https://api.broker.bgpkit.com/v3/latest.
use bgpkit_broker::BgpkitBroker;
let broker = BgpkitBroker::new();
for item in broker.latest().unwrap() {
println!("{}", item);
}
Structs§
- BgpkitBroker struct maintains the broker’s URL and handles making API queries.
- BGPKIT Broker data item.
- Iterator for BGPKIT Broker that iterates through one BrokerItem at a time.
- QueryParams represents the query parameters to the backend API.
Enums§
- Broker error enum.
- Sorting order enum